home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 034a / twview82.zip / TEXTDISP.INC < prev    next >
Text File  |  1991-02-04  |  6KB  |  199 lines

  1. procedure SortDistances( var D : distancearray; largest : sector );
  2. var
  3.   smallest : dist;
  4.   where    : sector;
  5.   s, t     : sector;
  6. begin
  7.   for s := 1 to largest - 1 do
  8.     begin
  9.       smallest := d[s];
  10.       where := s;
  11.       for t := s + 1 to largest do
  12.         if smallest.d > d[t].d then
  13.           begin
  14.             smallest := d[t];
  15.             where := t;
  16.           end; {for t}
  17.         d[where] := d[s];
  18.         d[s] := smallest;
  19.     end; {for s}
  20. end; {Sort Distances}
  21.  
  22. function SetupDistances : boolean;
  23. { return false if they aborted }
  24. var
  25.   s, n : integer;
  26. begin
  27.   s := GetSector;
  28.   if s <> 0 then
  29.     begin
  30.       FixDistances( s, distances );
  31.       for n := 1 to maxSector do distances[ n ].s := n;
  32.       SetUpDistances := true;
  33.     end {if}
  34.   else
  35.     SetUpDistances := false;
  36. end; {SetUpDistances}
  37.  
  38. function PortNumber( s : sector ) : PortIndex;
  39. { return the entry into the list of ports corresponding to port s;
  40.   return 0 if port not found. }
  41. var
  42.   i : portptr;
  43. begin
  44.   PortNumber := 0;
  45.   if space.Ports.top > 0 then
  46.     for i := 1 to space.Ports.top do
  47.       if space.Ports.data[ i ].where = s then
  48.         PortNumber := i;
  49. end; {PortNumber}
  50.  
  51. procedure DisplayPort( WhichPort : PortPtr );
  52. begin
  53.   if WhichPort = 0 then
  54.     writeln('Port data not found!')
  55.   else
  56.     with space.ports.data[ WhichPort ] do
  57.       write( ' F:', amts[ fuel ]:4, ' O:', amts[ organics] : 4, ' E:',
  58.                amts[ equipment ] : 4 );
  59. end; {DisplayPort}
  60.  
  61. function NoteNumber( s : sector ) : integer;
  62. { return the entry into the list of notes corresponding to sector s;
  63.   return 0 if note not found. }
  64. var
  65.   i : 1..MaxNote;
  66. begin
  67.   NoteNumber := 0;
  68.   if space.Ports.top > 0 then
  69.     for i := 1 to space.Notes.top do
  70.       if space.notes.data[ i ].reference = s then
  71.         NoteNumber := i;
  72. end; {PortNumber}
  73.  
  74. procedure WriteNote( s : sector );
  75. { print the note associated with sector s }
  76. var
  77.   n : 0..MaxNote;
  78. begin
  79.   n := NoteNumber( s );
  80.   if n = 0 then
  81.     write('Missing note! ')
  82.   else
  83.     write( ' ', space.notes.data[n].info );
  84. end; {write note}
  85.  
  86. procedure DisplaySector( s : sector; dist : integer );
  87. begin
  88.   with space.sectors[s] do
  89.     begin
  90.       write('Sector ', s:4);
  91.       if dist <> Error then
  92.         write( ' at distance ', dist : 2 );
  93.       if number = UnExplored then
  94.         write(' Unexplored sector');
  95.       if portType <> NotAPort then
  96.         begin
  97.           write(' port type ', status( portType ) );
  98.           if portType <> Class0 then
  99.             DisplayPort( portnumber( s ) );
  100.         end; {if port}
  101.       if (etc and StarDock) <> Nothing then
  102.         write(' Star Dock');
  103.       if (etc and HasFighters) <> Nothing then
  104.         write(' has fighters');
  105.       if (etc and NoteExists) <> Nothing then
  106.         WriteNote( s );
  107.       writeln;
  108.     end; {with}
  109. end; {DisplaySector}
  110.  
  111. type
  112.   WhichStuff = (any, PortOnly, NoteOnly, UnExpOnly );
  113.  
  114. procedure EliminateUnwanted( var distances   : distanceArray;
  115.                                  removeMe    : WhichStuff;
  116.                              var HowManyLeft : integer );
  117. { Remove the sectors you don't want in the list by pushing them to the back}
  118. var
  119.   whichSector : sector;
  120.   keep : boolean;
  121. begin
  122.   HowManyLeft := 0;
  123.   for whichSector := 1 to MaxSector do
  124.     begin
  125.       case removeMe of
  126.         any : keep := distances[ whichSector ].d <> maxint;
  127.         PortOnly : keep := space.sectors[whichSector].porttype <> NotAPort;
  128.         NoteOnly : keep := space.sectors[whichSector].etc and NoteExists
  129.                            <> Nothing;
  130.         UnExpOnly: keep := (space.sectors[whichSector].number = UnExplored)
  131.                            and (distances[ whichSector ].d <> maxint);
  132.       end; {case}
  133.       if keep then
  134.         begin
  135.           HowManyLeft := HowManyLeft + 1;
  136.           distances[ howManyLeft ] := distances[ whichSector ];
  137.         end; {if}
  138.     end; {for}
  139.   write('Total of ', HowManyLeft );
  140.   case removeMe of
  141.     any      : writeln(' sectors from base sector');
  142.     PortOnly : writeln(' known ports');
  143.     NoteOnly : writeln(' sectors with notes');
  144.     UnExpOnly: writeln(' unexplored sectors with known position');
  145.   end; {case}
  146. end; {EliminateUnwanted}
  147.  
  148. procedure FindSmallest( var distances : DistanceArray;
  149.                         lowest, highest : sector );
  150. { Examine the distance array from lowest to highest, and move the
  151. sector at smallest distance into the "lowest" slot. }
  152. var
  153.   temp     : dist;
  154.   s,
  155.   smallest : sector;
  156. begin
  157.   Smallest := lowest;
  158.   for s := lowest to highest do
  159.     if distances[ s ].d < distances[ smallest ].d then
  160.       smallest := s;
  161.   temp := distances[ smallest ];
  162.   distances[ smallest ] := distances[ lowest ];
  163.   distances[ lowest ] := temp;
  164. end; {FindSmallest}
  165.  
  166. procedure nearestStuff( Filter : WhichStuff );
  167. var
  168.   Number,
  169.   s, n : integer;
  170. begin
  171.   if SetUpDistances then
  172.     begin
  173.       EliminateUnwanted( distances, filter, Number );
  174.       if Number <> 0 then
  175.         begin
  176.           for n := 1 to Number do
  177.             begin
  178.               FindSmallest( distances, n, Number );
  179.               DisplaySector( distances[ n ].s, distances[n].d );
  180.               if n mod 20 = 0 then
  181.                 if not prompt( 'more? ') then
  182.                   exit;
  183.             end; {for}
  184.         end; {if}
  185.     end; {if}
  186. end; {nearport}
  187.  
  188. procedure SortPorts( var NumPorts : integer );
  189. var
  190.   s, n : integer;
  191. begin
  192.   NumPorts := 0;
  193.   if SetUpDistances then
  194.     begin
  195.       EliminateUnwanted( distances, PortOnly, NumPorts );
  196.       writeln('Sorting...');
  197.       SortDistances( distances, NumPorts )
  198.     end; {if}
  199. end; {SortPorts}